package Exercise;
public class Exercise2 
{ 
public  static void main(String[] args)
{
    Point start =new Point(2,3);//静态方法只能调用静态成员，动态方法都可以调用
    Point end =new Point(4,5);
    start.distence();
    System.out.println(start.toString());
    Line l=new Line(start,end);
    l.distence();

    //使用接口
    MyComparable p1=new Point(2, 3);
    MyComparable p2=new Point(1, 2);
    System.out.println(p1.compareto(p2));

    Point[] p4=new Point[]{new Point(2, 3),new Point(3, 4)};
    System.out.println(computil.max(p4));
}
}
class Point implements MyComparable
{
    public int x;
    public int y;
    public  Point(int x,int y)
    {
        this.x=x;
        this.y=y;
    }
    public int getX(){return x;}
    public int getY(){return y;}
    public double distence()
    {
        return Math.sqrt(x*x+y*y);
    }
    @Override
    public String toString()
    {
        return "("+x+","+y+")";
    }

    //实现接口
    @Override
    public int compareto(Object other){
        if(!(other instanceof Point))
        {
            throw new IllegalArgumentException();
        }
        Point otherPoint=(Point)other;
        double delta=distence()-otherPoint.distence();
        if(delta<0)
        {
            return -1;
        }
        else if(delta>0)
        {
            return 1;
        }
        else{
            return 0;
        }
    }
}
class Line
{
private Point start;
private Point end;
public Line(Point start,Point end)
{
    this.start=start;
    this.end=end;
}
 public double distence()
{
    double d1=Math.pow(start.x-end.x, 2);
    double d2=Math.pow(start.y-end.y, 2);
    return Math.sqrt(d1+d2);
}
}